#!/usr/bin/env python

from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine

from app.core.base_class import MyBase

from app.core.model.dw_meta_model import TbFile 
from app.core.model.dw_meta_model import TbFldLenNew

class DwmetaManager(MyBase):

    def __init__(self):
        MyBase.__init__(self)

        self.debug('DwmetaManager init begin')
        #engine = create_engine('mysql://root:123456@192.168.56.1/dwmeta?charset=utf8', echo=True)
        engine = create_engine('mysql://root:123456@192.168.56.1/dwmeta?charset=utf8')
        Session = sessionmaker(bind=engine)
        self.session = Session()
        self.debug('DwmetaManager init complemented.')
    
    def get_session(self):
        return self.session

'''
for i in session.query(TbFile).order_by(TbFile.tab_name):
    print i.tab_name
    for f in i.tb_flds:
        print f.col_name

    break
'''

if __name__ == '__main__':
    print 'test'
    dm = DwmetaManager()
    for i in dm.session.query(TbFile).order_by(TbFile.tab_name):
        print i.tab_name
    
